package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.ServiceType;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.IServiceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/serviceType")
public class ServiceTypeController extends BaseController {

    @Autowired
    private IServiceTypeService serviceTypeService;

//    @PreAuthorize("@ss.hasPermi('system:serviceType:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceType serviceType) {
        startPage();
        List<ServiceType> list = serviceTypeService.selectServiceTypeList(serviceType);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('system:serviceType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(serviceTypeService.selectServiceTypeById(id));
    }

//    @PreAuthorize("@ss.hasPermi('system:serviceType:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ServiceType serviceType) {
        return toAjax(serviceTypeService.insertServiceType(serviceType));
    }

//    @PreAuthorize("@ss.hasPermi('system:serviceType:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceType serviceType) {
        return toAjax(serviceTypeService.updateServiceType(serviceType));
    }

//    @PreAuthorize("@ss.hasPermi('system:serviceType:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(serviceTypeService.deleteServiceTypeByIds(ids));
    }
}